'''
Author: LHY 2601958675@qq.com
Date: 2023-05-16 11:45:08
LastEditors: LHY
LastEditTime: 2023-05-17 18:26:50
Description: 
'''
import pymongo


class Mong(object):
    def __init__(self):
        # 建立连接
        self.client = pymongo.MongoClient(host="localhost", port=5555)
        ## 指定数据库
        self.db = self.client["My_Demo"]

    # 插入数据
    def add_data(self):
        result = self.db.func.insert_one({"name": "张三", "age": 18, "sex": "男"})
        print(result)

    # 插入多条数据
    def add_many(self, data):
        result = self.db.func1.insert_many(data)
        print(result)

    # 查看多个函数
    def get_many(self):
        # result=self.db.func1.find({"name":"阿坤"})
        # print(result)
        result = self.db.func1.find()
        for data in result:
            print(data)


if __name__ == '__main__':
    mong = Mong()
    # mong.add_data()
    data = [
        {'name': '赵六', 'age': 18, 'sex': '男'},
        {'name': '王五', 'age': 18, 'sex': '男'},
        {'name': '阿坤', 'age': 18, 'sex': '男'}
    ]
    # mong.add_many(data)
    mong.get_many()
